const KoaRouter = require('koa-router')
const PartPurchaseService = require('../service/partPurchaseService.js')
const auth = require('../middleware/auth.js')
const code = require('../common/code.js')

const router = new KoaRouter()

router.get('/partPurchaseList', auth(['EDP']), async ctx => {
    ctx.body = code.getCode(code.SUCCESS, null, await PartPurchaseService.getList(ctx.session.user.store_id))
})

router.get('/partPurchase/:id', auth(['EDP']), async ctx => {
    ctx.body = code.getCode(code.SUCCESS, null, await PartPurchaseService.getOne(ctx.params.id, ctx.session.user.store_id))
})

router.post('/partPurchase', auth(['EDP']), async ctx => {
    ctx.request.body.store_id = ctx.session.user.store_id
    ctx.body = code.getCode(code.SUCCESS, null, await PartPurchaseService.insert(ctx.request.body))
})

router.put('/partPurchase/:id', auth(['EDP']), async ctx => {
    ctx.body = code.getCode(code.SUCCESS, null, await PartPurchaseService.update(ctx.params.id, ctx.session.user.store_id, ctx.request.body))
})

router.delete('/partPurchase/:id', auth(['EDP']), async ctx => {
    ctx.body = code.getCode(code.SUCCESS, null, await PartPurchaseService.del(ctx.params.id, ctx.session.user.store_id))
})

module.exports = router
